package com.dtw.ditouwang.repositories;

import com.dtw.ditouwang.beans.UserBean;

import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class UserRepository {
    private static UserRepository userRepository;
    private static UserBean userBean;
    ReadWriteLock readWriteLock=new ReentrantReadWriteLock();

    private UserRepository() {
    }

    public static UserRepository getInstance() {
        if (userRepository == null) {
            userRepository = new UserRepository();
        }
        return userRepository;
    }

    public UserBean getUserBean() {
        return userBean;
    }

    public int getUserID() {
        readWriteLock.writeLock().lock();
        if(userBean==null){
            return -1;
        }
        int userid=userBean.getData().getId();
        readWriteLock.writeLock().unlock();
        return userid;
    }

    public String getUserPhone() {
        return userBean.getData().getUsername();
    }

    public void setUserBean(UserBean userBean) {
        readWriteLock.writeLock().lock();
        this.userBean = userBean;
        readWriteLock.writeLock().unlock();
    }
}
